BluetoothCentralManager PRO
The BluetoothCentralManager namespace provides core functionality for managing Bluetooth Low Energy (BLE) operations as a central device. It supports scanning, connecting, disconnecting, and retrieving known or connected peripherals. This API is ideal for building custom Bluetooth workflows, interacting with smart devices, wearables, and IoT peripherals.
Properties
isScanning: Promise<boolean>
Returns whether the central manager is currently scanning for peripherals.
-
Type:
Promise<boolean> -
Example:
Methods
startScan(onDiscoverPeripheral, options?): Promise<void>
Starts scanning for BLE peripherals. The scan continues until you call
stopScan(). The callback will be triggered every time a peripheral is discovered.
Parameters
-
onDiscoverPeripheral: (peripheral, advertisementData, rssi) => void-
Callback triggered on discovery.
-
Arguments:
peripheral: ABluetoothPeripheralobjectadvertisementData: ABluetoothAdvertisementDataobjectrssi: Signal strength in dBm
-
-
options?: { services?: string[]; allowDuplicates?: boolean; solicitedServiceUUIDs?: string[] }services: An array of UUID strings to filter devices by servicesallowDuplicates: Iftrue, reports duplicates; iffalse(default), filters out repeated discoveriessolicitedServiceUUIDs: An array of UUID strings to filter devices by solicited services
BluetoothAdvertisementData
When using BluetoothCentralManager.startScan() to scan for Bluetooth peripherals, each discovered device includes an advertisementData object. This object contains key metadata extracted from the peripheral's BLE advertisement packets. It can help identify, filter, or categorize devices before establishing a connection.
Type Definition
Field Descriptions
Common Use Cases
- Filtering devices by
localName,serviceUUIDs, orisConnectable - Identifying vendor-specific devices using
manufacturerData - Estimating distance using
txPowerLevel+ RSSI - Understanding device intentions via
solicitedServiceUUIDs
Notes
- All fields are optional; some peripherals may omit certain fields.
manufacturerDataandserviceDataare rawDataobjects and must be parsed using manufacturer-specific formats.serviceUUIDsrepresent only advertised services. To get the full list of available services, callperipheral.discoverServices()after connecting.
Returns
Promise<void>
Example
stopScan(): Promise<void>
Stops an ongoing scan.
Returns
Promise<void>
Example
retrievePeripherals(ids: string[]): Promise<BluetoothPeripheral[]>
Retrieves known peripherals by their identifiers.
Parameters
ids: An array of peripheral UUID strings
Returns
Promise<BluetoothPeripheral[]>
Example
retrieveConnectedPeripherals(serviceUUIDs: string[]): Promise<BluetoothPeripheral[]>
Retrieves currently connected peripherals that provide at least one of the specified services.
Parameters
serviceUUIDs: An array of service UUID strings
Returns
Promise<BluetoothPeripheral[]>
Example
connect(peripheral, options?): Promise<void>
Establishes a connection to the specified peripheral.
Parameters
-
peripheral: ABluetoothPeripheralobject to connect to -
options?:startDelay?: number– Delay in seconds before connectingenableTransportBridging?: boolean– Enables transport bridging (advanced)requiresANCS?: boolean– Whether Apple Notification Center Service is requiredenableAutoReconnect?: boolean– Whether to auto-reconnect if disconnectednotifyOnConnection?: boolean- Whether to notify when the connection is establishednotifyOnDisconnection?: boolean- Whether to notify when the connection is disconnectednotifyOnNotification?: boolean- Whether to notify when a notification is received
Returns
Promise<void>
Example
disconnect(peripheral): Promise<void>
Disconnects from the specified peripheral. This is a non-blocking operation.
Parameters
peripheral: ABluetoothPeripheralobject
Returns
Promise<void>
Notes
- Physical disconnection is not guaranteed if other apps are connected to the same peripheral.
- From the app's perspective, the device is considered disconnected and
onDisconnectedwill be triggered.
Example
Workflow Example
Best Practices
- Always call
stopScan()when scanning is no longer needed to save battery and reduce system load. - Make sure Bluetooth permissions are granted before using these APIs.
- After connecting to a peripheral, call
discoverServices()followed bydiscoverCharacteristics()before reading or writing data.
